'use strict';

const Service = require('egg').Service;

class BlogService extends Service {
  async list() {
        let res=await this.app.mysql.query(`select * from blog`)
        return res
  }
  async addlist(query){
    let {title,text,name,img}=query
    let res=await this.app.mysql.query(`insert into blog (title,text,time,name,img) values ('${title}','${text}',now(),'${name}','${img}') `)
    return res
  }
  async del(id){
      let res=await this.app.mysql.query(`delete from blog where id=${id}`)
      return res
  }

  async updata(query){
      let {id,name,title,text,img}=query
      let res=await this.app.mysql.query(`update blog set name='${name}',time=now(),text='${text}',img='${img}',title='${title}' where id=${id}`)
      return res
  }
}

module.exports = BlogService;
